package com.hy;

/**
 * Created With IntelliJ IDEA.
 * Descriptions:121. 买卖股票的最佳时机
 * <p>
 * User:Mr.Du
 * Date:2024/7/30
 * Time:14:59
 */
public class MaxProfit {

    public int maxProfit(int[] prices) {
        int res = 0;
        int minPrice = prices[0];
        for (int i = 1; i < prices.length; i++) {
            res = Math.max(res, prices[i] - minPrice);
            minPrice = Math.min(minPrice, prices[i]);
        }
        return res;
    }
}
